package validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import command.QuestionForm;

@Component
public class QuestionFormValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return QuestionForm.class.equals(clazz);
	}
	
	@Override
	public void validate(Object target, Errors errors) {
		QuestionForm form = (QuestionForm) target;
		if(form.getQuestion() == null || form.getQuestion().isEmpty()){
			errors.rejectValue("question","empty");
		}
	}
}